﻿// For an introduction to the Page Control template, see the following documentation:
// http://go.microsoft.com/fwlink/?LinkId=232511
(function () {
    "use strict";

    WinJS.UI.Pages.define("/pages/charts/charts.html", {

        // NOTE: init is like the constructor for your page.
        init: function (element, options) {
            this.options = options;

            var data = {
                population: Data.getPopulationData(options),
                commute: Data.getCommuteData(options),
                housing: Data.getHousingData(options)
            };
            var that = this;
            // NOTE: we want to not process the rest of the HTML (e.g. light up the Repeater controls)
            //       until we have the data, so we return a Promise from init in order to cause the 
            //       page rendering logic to wait. Here we use WinJS.Promise.join which waits for all
            //       three of the incoming promises to finish.
            return WinJS.Promise.join(data).then(function (data) {
                that.population = data.population;
                that.commute = data.commute;
                that.housing = data.housing;
            });
        },

        // NOTE: processed is called after the page content has rendered and controls on the
        //       page have been activated (e.g. WinJS.UI.processAll). Here we are further adding
        //       data binding processing to the page by chaining it in (note that again we return
        //       the Promise so that further work will wait until the first binding pass is done.
        processed: function () {
            return WinJS.Binding.processAll(this.element, this);
        },

    });

})();
